package br.com.rglariguet.rgportal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import br.com.rglariguet.rgportal.Usuario;
import br.com.rglariguet.rgportal.dao.UsuarioDAO;

@Controller
@SessionAttributes("usuarioLogado")
public class LoginController {
	
	@Autowired
	private UsuarioDAO usuarioDAO; 

	@RequestMapping("/admin/inicio")
	public String index(ModelMap model){
		Usuario user = (Usuario) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		model.addAttribute("usuarioLogado", user.getNome());
		return "/admin/index";
	}
	
	@RequestMapping("/login-form")
	public String login(ModelMap model){
		return "/usuarios/login-form";
	}
	
	@RequestMapping("/loginerror")
	public String loginError(ModelMap model){
		model.addAttribute("erroLogin","Erro ao logar");
		return "/usuarios/login-form";
	}
	
}
